// @ts-nocheck
import { AuthClientOption } from "../../src/model/authClient.model";
import { AuthClient } from "../../src"
import { LogEventType } from '../../src/model/logCollect.model'

const ac = new AuthClient({
    // routerMode: 'history', // 'history'||'hash' 根据实际项目路由情况选择
    SSOServer: 'https://auth-test.jxwrd.gov.cn',
    // resourceCode: 'code',
    routerMode: 'hash', // 'history'||'hash' 根据实际项目路由情况选择
    // SSOServer: 'https://auth-dev.jxwrd.gov.cn',
    resourceCode: '964a8329500649a6aaf7a6b4eb14fbe8',
    method: 'custom',
    logCollect: {
        logServer: 'http://foura.test.jxwrd.gov.cn',
        production: true,
    },
} as AuthClientOption)

ac.on('inited', function (e) {
    //console.log(e)
})

// 日志捕获错误
ac.on('logError', function (e) {
    console.log(e)
})

ac.on('error', function (e) {
  alert(e.msg || e)
})


const btn = document.getElementById('btn')
btn.onclick = () => {
    ac.logout().then(res => { console.log(res) })
}

// 登录
document.getElementById('logInBtn').onclick = () => {
    let username = document.getElementById('account')['value']
    let password = document.getElementById('password')['value']
    ac.login({
        username: username, // （必填）账号
        password: password, // （必填）密码
        loginCode: '',
    }).then((res) => {
        //console.log(res)
    })
}
// 图片验证码
document.getElementById('verification').onclick = () => {
    ac.getImageCode().then(res => {
        console.log(res)
    })
}

//短信验证码
document.getElementById('sms').onclick = () => {
    const phone = document.getElementById('account')['value']
    ac.sendSmsCode(phone).then(res => {
        if (res.code === 0) {
            console.log('短信验证码限流时间', res.data)
        }
        console.log(res)
    })
}

// 手机登录
document.getElementById('phone').onclick = () => {
    const smsMob = document.getElementById('account')['value']
    const smsCode = document.getElementById('password')['value']
    ac.loginByPhone({ smsMob, smsCode }).then(res => {
        console.log(res)
    })
}
/**
 * 钉钉二维码
 * **/
// ac.qrGzt({ eleId: 'login_QRCode' })
/*ac.qrCode({ eleId: 'login_QRCode', redirectUrl: location.href  })
// 清除二维码
document.getElementById('clean').onclick = () => {
    ac.destroyQr()
}*/

document.getElementById('event').onclick = () => {
    ac.logRecordEvent('按钮')
    /*ac.serverLogout().then((res) => {
        console.log(res)
    })*/
}

/*清除国密人次认证弹框*/
document.getElementById('modal').onclick = () => {
    ac.destroyModal()
}
